package com.ruoyi.integration.kafka;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description : KafkaConsumer
 * @Author : Bruce Lee
 * @CreateTime : 2025/2/18
 */

@Slf4j
@Component
public class KafkaConsumer {


    @KafkaListener(topics = {"test", "test2"})
    public void func(List<ConsumerRecord<String, Object>> records, Acknowledgment ack){
        for (ConsumerRecord<String, Object> record : records) {
            log.info("topic: {}, partition: {}, offset: {}, key: {}, value: {}", record.topic(), record.partition(), record.offset(), record.key(), record.value());

            // 确认消息已消费
            ack.acknowledge();
        }
    }

}
